package com.demostic.demostic_test.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.style.ImageSpan;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.core.content.ContextCompat;

import com.demostic.demostic_test.R;
import com.demostic.demostic_test.base.BaseActivity;
import com.demostic.demostic_test.utils.Constants;
import com.demostic.demostic_test.utils.DisplayUtil;

import java.util.Locale;

public class ApGuideActivity extends BaseActivity implements View.OnClickListener {
    final String TAG = ApGuideActivity.class.getSimpleName();
    Button bt_next;
    Context context;
    private Drawable drawable;
    ImageView image_back;
    private ImageView iv1;
    private ImageView iv2;
    private ImageView ivGone;
    String local;
    int offset;
    private RelativeLayout rl_step3;
    private String str_tip;
    private String subdomain;
    private int subdomainId;
    TextView tv_didi;

    @Override // com.demostic.demostic_test.base.BaseActivity, android.support.v7.app.AppCompatActivity, android.support.v4.app.FragmentActivity, android.app.Activity
    @RequiresApi(api = 21)
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ap_guide);
        getSubdomain();
        initView();
    }

    public void getSubdomain() {
        Bundle bundle;
        this.local = Locale.getDefault().getLanguage();
        Intent intent = getIntent();
        if (intent != null && (bundle = intent.getExtras()) != null) {
            this.subdomain = bundle.getString("subdomain");
            this.subdomainId = bundle.getInt("subdomainId");
        }
    }

    @RequiresApi(api = 21)
    private void initView() {
        this.context = this;
        if (this.local.equals("en")) {
            this.offset = 16;
        } else {
            this.offset = 9;
        }
        this.bt_next = (Button) findViewById(R.id.bt_next);
        this.tv_didi = (TextView) findViewById(R.id.tv_didi);
        this.rl_step3 = (RelativeLayout) findViewById(R.id.relative_step3);
        this.image_back = (ImageView) findViewById(R.id.image_back);
        this.iv1 = (ImageView) findViewById(R.id.image_step1);
        this.iv2 = (ImageView) findViewById(R.id.image_step2);
        this.ivGone = (ImageView) findViewById(R.id.iamge_step_gone);
        if (this.subdomain.equals("ilifex900") || this.subdomain.equals(Constants.subdomain_x800) || this.subdomain.equals(Constants.subdomain_x901) || this.subdomain.equals("ilifex900")) {
            this.str_tip = getString(R.string.ap_guide_aty_900tip2);
        } else {
            this.str_tip = getString(R.string.ap_guide_aty_tip2);
        }
        SpannableString spannableString = new SpannableString(this.str_tip);
        if (this.subdomain.equals("ilifex660") || this.subdomain.equals("ilifex660")) {
            this.drawable = ContextCompat.getDrawable(this.context, R.drawable.sixty_guide_btn);
        } else if (this.subdomain.equals(Constants.subdomain_x610)) {
            this.drawable = ContextCompat.getDrawable(this.context, R.drawable.sixty_guide_btn2);
        } else if (this.subdomain.equals(Constants.subdomain_x782)) {
            this.drawable = ContextCompat.getDrawable(this.context, R.drawable.seventy782_guide_btn);
        } else if (this.subdomain.equals(Constants.subdomain_x785) || this.subdomain.equals(Constants.subdomain_x786) || this.subdomain.equals(Constants.subdomain_x787) || this.subdomain.equals(Constants.subdomain_x790)) {
            this.drawable = ContextCompat.getDrawable(this.context, R.drawable.seventy_guide_btn);
        } else if (this.subdomain.equals(Constants.subdomain_x800)) {
            this.drawable = ContextCompat.getDrawable(this.context, R.drawable.eighty_guide_btn);
        } else if (this.subdomain.equals("ilifex900") || this.subdomain.equals(Constants.subdomain_x901) || this.subdomain.equals("ilifex900")) {
            this.drawable = ContextCompat.getDrawable(this.context, R.drawable.ninety_guide_btn);
        } else if (this.subdomain.equals("zhiyitest") || this.subdomain.equals(Constants.subdomain_x420) || this.subdomain.equals(Constants.subdomain_x620)) {
            this.drawable = ContextCompat.getDrawable(this.context, R.drawable.forty_guide_btn);
        }
        setIamgeSpan(spannableString, this.drawable);
        if (this.subdomain.equals("ilifex660") || this.subdomain.equals("ilifex660")) {
            DisplayUtil.setApGuideStep(this.iv1, this.iv2, ContextCompat.getDrawable(this.context, R.drawable.sixty_guide1), ContextCompat.getDrawable(this.context, R.drawable.sixty_guide2));
        } else if (this.subdomain.equals(Constants.subdomain_x610)) {
            DisplayUtil.setApGuideStep(this.iv1, this.iv2, ContextCompat.getDrawable(this.context, R.drawable.sixty_610guide1), ContextCompat.getDrawable(this.context, R.drawable.sixty_610guide2));
        } else if (this.subdomain.equals(Constants.subdomain_x782)) {
            DisplayUtil.setApGuideStep(this.iv1, this.iv2, ContextCompat.getDrawable(this.context, R.drawable.seventy782_guide1), ContextCompat.getDrawable(this.context, R.drawable.seventy782_guide2));
            this.rl_step3.setVisibility(0);
            this.ivGone.setImageDrawable(ContextCompat.getDrawable(this.context, R.drawable.seventy782_guide3));
        } else if (this.subdomain.equals(Constants.subdomain_x785) || this.subdomain.equals(Constants.subdomain_x786) || this.subdomain.equals(Constants.subdomain_x787) || this.subdomain.equals(Constants.subdomain_x790)) {
            DisplayUtil.setApGuideStep(this.iv1, this.iv2, ContextCompat.getDrawable(this.context, R.drawable.seventy_guide1), ContextCompat.getDrawable(this.context, R.drawable.seventy_guide2));
            this.rl_step3.setVisibility(0);
            this.ivGone.setImageDrawable(ContextCompat.getDrawable(this.context, R.drawable.seventy_guide3));
        } else if (this.subdomain.equals(Constants.subdomain_x800)) {
            DisplayUtil.setApGuideStep(this.iv1, this.iv2, ContextCompat.getDrawable(this.context, R.drawable.eighty_guide1), ContextCompat.getDrawable(this.context, R.drawable.eighty_guide2));
        } else if (this.subdomain.equals("ilifex900") || this.subdomain.equals(Constants.subdomain_x901) || this.subdomain.equals("ilifex900")) {
            DisplayUtil.setApGuideStep(this.iv1, this.iv2, ContextCompat.getDrawable(this.context, R.drawable.ninety_guide1), ContextCompat.getDrawable(this.context, R.drawable.ninety_guide2));
        } else if (this.subdomain.equals("zhiyitest") || this.subdomain.equals(Constants.subdomain_x420) || this.subdomain.equals(Constants.subdomain_x620)) {
            DisplayUtil.setApGuideStep(this.iv1, this.iv2, ContextCompat.getDrawable(this.context, R.drawable.forty_guide1), ContextCompat.getDrawable(this.context, R.drawable.forty_guide2));
        }
        this.bt_next.setOnClickListener(this);
        this.image_back.setOnClickListener(this);
    }

    private void setIamgeSpan(SpannableString spanStr, Drawable drawable2) {
        drawable2.setBounds(0, 0, drawable2.getIntrinsicWidth(), drawable2.getIntrinsicHeight());
        spanStr.setSpan(new VerticalIamgeSpan(drawable2), this.offset, this.offset + 1, 17);
        this.tv_didi.setText(spanStr);
    }

    @Override // android.view.View.OnClickListener
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.image_back /* 2131755189 */:
                finish();
                return;
            case R.id.bt_next /* 2131755203 */:
                Intent i = new Intent(this.context, FirstApActivity.class);
                i.putExtra("subdomain", this.subdomain);
                startActivity(i);
                return;
            default:
                return;
        }
    }

    public class VerticalIamgeSpan extends ImageSpan {
        public VerticalIamgeSpan(@NonNull Drawable d) {
            super(d);
        }

        @Override // android.text.style.DynamicDrawableSpan, android.text.style.ReplacementSpan
        public int getSize(@NonNull Paint paint, CharSequence text, int start, int end, @Nullable Paint.FontMetricsInt fm) {
            super.getSize(paint, text, start, end, fm);
            Rect rect = getDrawable().getBounds();
            if (fm != null) {
                Paint.FontMetricsInt fmPaint = paint.getFontMetricsInt();
                int fontHeight = fmPaint.bottom - fmPaint.top;
                int drHeight = rect.bottom - rect.top;
                int top = (drHeight / 2) - (fontHeight / 4);
                int bottom = (drHeight / 2) + (fontHeight / 4);
                fm.ascent = -bottom;
                fm.top = -bottom;
                fm.bottom = top;
                fm.descent = top;
            }
            return rect.right;
        }

        @Override // android.text.style.DynamicDrawableSpan, android.text.style.ReplacementSpan
        public void draw(@NonNull Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, @NonNull Paint paint) {
            super.draw(canvas, text, start, end, x, top, y, bottom, paint);
            Drawable drawable = getDrawable();
            canvas.save();
            canvas.translate(x, (float) ((((bottom - top) - drawable.getBounds().bottom) / 2) + top));
            drawable.draw(canvas);
            canvas.restore();
        }
    }
}
